using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerFire : MonoBehaviour
{
    public GameObject bullet;
    float bullet_block;
    public int FireSpeed;
    
    // Start is called before the first frame update
    void Start()
    {
        FireSpeed = 20;
    }

    // Update is called once per frame
    void Update()
    {
        Fire();
        
    }
    private void FixedUpdate()
    {
        if (bullet_block > 0) bullet_block--;
    }
    private void Fire()
    {
        
        Vector3 local=transform.position;
        if (Input.GetKey(KeyCode.J)&&bullet_block<=0)
        {
            if (GetComponent<PlayerInfo>().level == 1)
            {
                Instantiate(bullet, local, Quaternion.identity);
                bullet_block = FireSpeed;
            }
            if(GetComponent<PlayerInfo>().level == 2)
            {
                Instantiate(bullet,local+new Vector3(0.5f,0,0), Quaternion.identity);
                Instantiate(bullet,local+new Vector3(-0.5f,0,0), Quaternion.identity);
                bullet_block=FireSpeed;
            }
            if(GetComponent<PlayerInfo>().level >= 3)
            {
                Instantiate(bullet, local, Quaternion.identity);
                Instantiate(bullet, local + new Vector3(0.5f, 0, 0), Quaternion.identity);
                Instantiate(bullet, local + new Vector3(-0.5f, 0, 0), Quaternion.identity);
                bullet_block = FireSpeed;
            }
        }
    }
    
}
